geom_density(data=d, aes(x=turnout1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3)
ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3)
ggplot() +
geom_density(data=d, aes(x=turnout1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("gold3", "firebrick"), name="") +
scale_fill_manual(values=c("gold3", "firebrick"), name="") +
xlab("Turnout") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14))
### Turnout in 1994
ggplot() +
geom_density(data=d, aes(x=turnout1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("gold3", "firebrick"), name="") +
scale_fill_manual(values=c("gold3", "firebrick"), name="") +
xlab("Turnout") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Turnout in 1994
ggplot() +
geom_density(data=d, aes(x=turnout1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Turnout") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Turnout in 2017
ggplot() +
geom_density(data=d, aes(x=turnout2017*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Turnout (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Republikaner in 1994
ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Turnout (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Republikaner in 1994
ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
#scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Turnout (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Republikaner in 1994
ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
#scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Republikaner vote share (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Republikaner in 1994
ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
#scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab(expression(paste(italic("Republikaner"), " vote share (%)"))) +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Republikaner in 1994
ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
#scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab(expression(paste(bold(italic("Republikaner"), " vote share (%)")))) +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Republikaner in 1994
ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
#scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Republikaner vote share (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### AfD in 2017
ggplot() +
geom_density(data=d, aes(x=afd_share2017*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
#scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Republikaner vote share (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### AfD in 2017
ggplot() +
geom_density(data=d, aes(x=afd_share2017*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
#scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("AfD vote share (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Republikaner in 1994
ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_x_continuous(limits = c(0,50)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Republikaner vote share (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### AfD in 2017
ggplot() +
geom_density(data=d, aes(x=afd_share2017*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("AfD vote share (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Turnout in 1994
turnout1994 <- ggplot() +
geom_density(data=d, aes(x=turnout1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Turnout (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Turnout in 2017
turnout2017 <- ggplot() +
geom_density(data=d, aes(x=turnout2017*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_x_continuous(limits = c(0,100)) +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Turnout (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### Republikaner in 1994
rep1994 <- ggplot() +
geom_density(data=d, aes(x=rep_share1994*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("Republikaner vote share (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
### AfD in 2017
afd2017 <- ggplot() +
geom_density(data=d, aes(x=afd_share2017*100, col=as.factor(east), fill=as.factor(east)), alpha=.3) +
theme_bw() +
scale_color_manual(values=c("firebrick", "gold3"), name="") +
scale_fill_manual(values=c("firebrick", "gold3"), name="") +
xlab("AfD vote share (%)") +
ylab("Density") +
theme(axis.title=element_text(face="bold",size=14),
legend.position = "bottom")
ggsave("turnout1994_hist.png", turnout1994, width=8, height=6)
ggsave("turnout1994_hist.png", turnout1994, width=8, height=6)
ggsave("turnout2017_hist.png", turnout2017, width=8, height=6)
ggsave("rep1994_hist.png", rep1994, width=8, height=6)
ggsave("afd2017_hist.png", afd2017, width=8, height=6)
### Create data frame: units of analysis
### January 10, 2020
# Preparation -------------------------------------------------------------
### Set working directory
setwd("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State")
### Empty environment
rm(list=ls())
### load packages
library(foreign)
library(ggplot2)
library(tidyr)
library(dplyr)
library(maptools)
library(gridExtra)
library(ggmap)
library(data.table)
library(raster)
library(rgdal)
library(sp)
library(grid)
library(gridExtra)
library(Matching)
library(stargazer)
library(lmtest)
library(sandwich)
library(xtable)
library(geosphere)
library(readxl)
# Run pre-processing script and get data from Abramson shapefiles ---------
### Notes: Abramson's data has IDs, but not the state names.
### Abramson fixes some of the issues in his shapefiles in a pre-processing script
### The shapefiles have state names, but all IDs are 0. So need to put both together
### Run pre-processing script and get relevant data
# run script
source("/Users/hanslueders/Dropbox (IPL)/Data copy/Shape_Files_For_Anna copy/pre_processing_script_hl.R")
View(data_q)
table(data_q$Name)
### Create data frame: units of analysis
### January 10, 2020
# Preparation -------------------------------------------------------------
### Set working directory
setwd("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State")
### Empty environment
rm(list=ls())
### load packages
library(foreign)
library(ggplot2)
library(tidyr)
library(dplyr)
library(maptools)
library(gridExtra)
library(ggmap)
library(data.table)
library(raster)
library(rgdal)
library(sp)
library(grid)
library(gridExtra)
library(Matching)
library(stargazer)
library(lmtest)
library(sandwich)
library(xtable)
library(geosphere)
library(readxl)
# Run pre-processing script and get data from Abramson shapefiles ---------
### Notes: Abramson's data has IDs, but not the state names.
### Abramson fixes some of the issues in his shapefiles in a pre-processing script
### The shapefiles have state names, but all IDs are 0. So need to put both together
### Run pre-processing script and get relevant data
# run script
source("/Users/hanslueders/Dropbox (IPL)/Data copy/Shape_Files_For_Anna copy/pre_processing_script_hl.R")
# get data
d <- data_q
# drop files no longer needed
rm(data_list, data_list2, data_q, files, i, years)
# change column names to lower case
colnames(d)[1:2] <- c("name", "year")
### combine with Abramson replication files
# load file
ab <- read.dta("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/AbramsonData.dta")
# round area, X, and Y
d$Area2 <- round(d$Area, digits=0)
d$X2 <- round(d$X, digits=0)
d$Y2 <- round(d$Y, digits=0)
ab$Area2 <- round(ab$Area, digits=0)
ab$X2 <- round(ab$X, digits=0)
ab$Y2 <- round(ab$Y, digits=0)
# merge
d.final <- merge(d, ab, by=c("X2","Y2","Area2", "year"), all.x=T)
# remove X, Y, Area
d.final$Area <- d.final$Area.x
d.final$X <- d.final$X.x
d.final$Y <- d.final$Y.x
d.final$Area2 <- NULL
d.final$X2 <- NULL
d.final$Y2 <- NULL
d.final$Area.x <- NULL
d.final$X.x <- NULL
d.final$Y.x <- NULL
d.final$Area.y <- NULL
d.final$X.y <- NULL
d.final$Y.y <- NULL
### Create data frame: units of analysis
### January 10, 2020
# Preparation -------------------------------------------------------------
### Set working directory
setwd("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State")
### Empty environment
rm(list=ls())
### load packages
library(foreign)
library(ggplot2)
library(tidyr)
library(dplyr)
library(maptools)
library(gridExtra)
library(ggmap)
library(data.table)
library(raster)
library(rgdal)
library(sp)
library(grid)
library(gridExtra)
library(Matching)
library(stargazer)
library(lmtest)
library(sandwich)
library(xtable)
library(geosphere)
library(readxl)
# Run pre-processing script and get data from Abramson shapefiles ---------
### Notes: Abramson's data has IDs, but not the state names.
### Abramson fixes some of the issues in his shapefiles in a pre-processing script
### The shapefiles have state names, but all IDs are 0. So need to put both together
### Run pre-processing script and get relevant data
# run script
source("/Users/hanslueders/Dropbox (IPL)/Data copy/Shape_Files_For_Anna copy/pre_processing_script_hl.R")
# get data
d <- data_q
# drop files no longer needed
rm(data_list, data_list2, data_q, files, i, years)
# change column names to lower case
colnames(d)[1:2] <- c("name", "year")
table(d$name)
### combine with Abramson replication files
# load file
ab <- read.dta("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/AbramsonData.dta")
### combine with Abramson replication files
# load file
ab <- read.dta("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State/AbramsonData.dta")
# round area, X, and Y
d$Area2 <- round(d$Area, digits=0)
d$X2 <- round(d$X, digits=0)
d$Y2 <- round(d$Y, digits=0)
ab$Area2 <- round(ab$Area, digits=0)
ab$X2 <- round(ab$X, digits=0)
ab$Y2 <- round(ab$Y, digits=0)
# merge
d.final <- merge(d, ab, by=c("X2","Y2","Area2", "year"), all.x=T)
# remove X, Y, Area
d.final$Area <- d.final$Area.x
d.final$X <- d.final$X.x
d.final$Y <- d.final$Y.x
d.final$Area2 <- NULL
d.final$X2 <- NULL
d.final$Y2 <- NULL
d.final$Area.x <- NULL
d.final$X.x <- NULL
d.final$Y.x <- NULL
d.final$Area.y <- NULL
d.final$X.y <- NULL
d.final$Y.y <- NULL
View(d.final)
table(d.final$name)
### Create data frame: units of analysis
### January 10, 2020
# Preparation -------------------------------------------------------------
### Set working directory
setwd("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State")
### Empty environment
rm(list=ls())
### load packages
library(foreign)
library(ggplot2)
library(tidyr)
library(dplyr)
library(maptools)
library(gridExtra)
library(ggmap)
library(data.table)
library(raster)
library(rgdal)
library(sp)
library(grid)
library(gridExtra)
library(Matching)
library(stargazer)
library(lmtest)
library(sandwich)
library(xtable)
library(geosphere)
library(readxl)
# Run pre-processing script and get data from Abramson shapefiles ---------
### Notes: Abramson's data has IDs, but not the state names.
### Abramson fixes some of the issues in his shapefiles in a pre-processing script
### The shapefiles have state names, but all IDs are 0. So need to put both together
### Run pre-processing script and get relevant data
# run script
source("/Users/hanslueders/Dropbox (IPL)/Data copy/Shape_Files_For_Anna copy/pre_processing_script_hl.R")
# get data
d <- data_q
# drop files no longer needed
rm(data_list, data_list2, data_q, files, i, years)
# change column names to lower case
colnames(d)[1:2] <- c("name", "year")
### combine with Abramson replication files
# load file
ab <- read.dta("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State/AbramsonData.dta")
# round area, X, and Y
d$Area2 <- round(d$Area, digits=0)
d$X2 <- round(d$X, digits=0)
d$Y2 <- round(d$Y, digits=0)
ab$Area2 <- round(ab$Area, digits=0)
ab$X2 <- round(ab$X, digits=0)
ab$Y2 <- round(ab$Y, digits=0)
# merge
d.final <- merge(d, ab, by=c("X2","Y2","Area2", "year"), all.x=T)
# remove X, Y, Area
d.final$Area <- d.final$Area.x
d.final$X <- d.final$X.x
d.final$Y <- d.final$Y.x
d.final$Area2 <- NULL
d.final$X2 <- NULL
d.final$Y2 <- NULL
d.final$Area.x <- NULL
d.final$X.x <- NULL
d.final$Y.x <- NULL
d.final$Area.y <- NULL
d.final$X.y <- NULL
d.final$Y.y <- NULL
### save
write.dta(d.final, "DataFrame.dta", convert.factors = "string")
### Create data frame: units of analysis
### January 10, 2020
# Preparation -------------------------------------------------------------
### Set working directory
setwd("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State")
### Empty environment
rm(list=ls())
### load packages
library(foreign)
library(ggplot2)
library(tidyr)
library(dplyr)
library(maptools)
library(gridExtra)
library(ggmap)
library(data.table)
library(raster)
library(rgdal)
library(sp)
library(grid)
library(gridExtra)
library(Matching)
library(stargazer)
library(lmtest)
library(sandwich)
library(xtable)
library(geosphere)
library(readxl)
# Run pre-processing script and get data from Abramson shapefiles ---------
### Notes: Abramson's data has IDs, but not the state names.
### Abramson fixes some of the issues in his shapefiles in a pre-processing script
### The shapefiles have state names, but all IDs are 0. So need to put both together
### Run pre-processing script and get relevant data
# run script
source("/Users/hanslueders/Dropbox (IPL)/Data copy/Shape_Files_For_Anna copy/pre_processing_script_hl.R")
# get data
d <- data_q
# drop files no longer needed
rm(data_list, data_list2, data_q, files, i, years)
# change column names to lower case
colnames(d)[1:2] <- c("name", "year")
### combine with Abramson replication files
# load file
ab <- read.dta("/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State/AbramsonData.dta")
# round area, X, and Y
d$Area2 <- round(d$Area, digits=0)
d$X2 <- round(d$X, digits=0)
d$Y2 <- round(d$Y, digits=0)
ab$Area2 <- round(ab$Area, digits=0)
ab$X2 <- round(ab$X, digits=0)
ab$Y2 <- round(ab$Y, digits=0)
# merge
d.final <- merge(d, ab, by=c("X2","Y2","Area2", "year"), all.x=T)
# remove X, Y, Area
d.final$Area <- d.final$Area.x
d.final$X <- d.final$X.x
d.final$Y <- d.final$Y.x
d.final$Area2 <- NULL
d.final$X2 <- NULL
d.final$Y2 <- NULL
d.final$Area.x <- NULL
d.final$X.x <- NULL
d.final$Y.x <- NULL
d.final$Area.y <- NULL
d.final$X.y <- NULL
d.final$Y.y <- NULL
### save
write.dta(d.final, "/Users/hanslueders/Dropbox (IPL)/Data copy/Final data/State/DataFrame.dta", convert.factors = "string")
